var express = require('express');
var router = express.Router();
const servicesService=require('../service/servicesService')

// 查询
router.get('/',async function (req, res, next) {
  let { id, current, size } = req.query;
  let searchObj = {};
  if (id) {
    searchObj.adminId = id
  }
  let data = await servicesService.findAll(searchObj
    , { current: parseInt(current) || 1, size: parseInt(size) || 4 });
  res.send(data)
});

//根据id查询
router.get('/:id', async function (req, res) {
  let id = req.params.id;
  let data = await servicesService.findById(id);
  
  res.send(data);
})

//插入
router.post('/', async function (req, res) {
  let data =await  servicesService.insert(req.body);
  res.send(data)
})

//修改
router.put('/:id', async function (req, res) {
  let id = req.params.id;
  let data = await servicesService.update(id, req.body);
  res.send(data);
})

//删除
router.delete('/:id', async function (req, res) {
  let id = req.params.id;
  let data =await  servicesService.delete(id);
  res.send(data);

})

module.exports = router;
